<template>
  <TopNav title="修改信息"/>
  <div class="container">
    <van-cell-group class="form">
      <van-field v-model="patientDesc.patientNumber" label="住院号" placeholder="请填写住院号"/>
      <van-field v-model="patientDesc.patientName" label="姓名" placeholder="请填写姓名"/>
      <van-field v-model="patientDesc.patientSex" label="性别" placeholder="请填写性别"/>
      <van-field v-model="patientDesc.patientAge" label="年龄" placeholder="请填写年龄"/>
      <van-field v-model="patientDesc.height" label="身高" placeholder="请填写身高"/>
      <van-field v-model="patientDesc.height" label="体重" placeholder="请填写体重"/>
      <van-field type="textarea" rows="2" v-model="patientDesc.disease" label="所患疾病" placeholder="请填写"/>
    </van-cell-group>
    <el-button @click="http_patient_update" class="button" type="success" round>确认</el-button>
  </div>
</template>

<script setup>
import patientAxios from "@/api/patient.js"
import {useDataStore} from "@/stores/dataStore.js";
import {onMounted, reactive} from "vue";
import {useRoute, useRouter} from 'vue-router'
import TopNav from "@/components/TopNav/Back.vue"

const route = useRoute()
const router = useRouter()
const dataStore = useDataStore()
//患者详情
const patientDesc = reactive({
  patientId: '',
  patientName: "",
  patientNumber: "",
  patientSex: "",
  patientAge: "",
  height: "",
  weight: "",
  disease: "",
  assessmentDate: "",
  assessmentResult: "",
  patientNRS: "",
  patientMUST: "",
  treatmentStage: "",
})
onMounted(() => {
  http_patient_findById()
})
/**
 * 查询患者详情
 */
const http_patient_findById = () => {
  patientAxios.patient_findById({
    patientId: route.params.name
  }).then(res => {
    if (res.data.code == 200) {
      patientDesc.patientId = res.data.data.patientId;
      patientDesc.patientName = res.data.data.patientName;
      patientDesc.patientNumber = res.data.data.patientNumber;
      patientDesc.patientSex = res.data.data.patientSex;
      patientDesc.patientAge = res.data.data.patientAge;
      patientDesc.height = res.data.data.height;
      patientDesc.weight = res.data.data.weight;
      patientDesc.disease = res.data.data.disease;
      patientDesc.assessmentDate = res.data.data.assessmentDate;
      patientDesc.assessmentResult = res.data.data.assessmentResult;
      patientDesc.patientNRS = res.data.data.patientNRS;
      patientDesc.patientMUST = res.data.data.patientMUST;
      patientDesc.treatmentStage = res.data.data.treatmentStage;
      patientDesc.hospitalizationStage = res.data.data.hospitalizationStage;
    } else {
      ElMessage.error(res.data.data.message)
    }
  })
}
/**
 * 修改信息
 */
const http_patient_update = () => {
  patientAxios.patient_update({
    patientId: patientDesc.patientId,
    patientName: patientDesc.patientName,
    patientNumber: patientDesc.patientNumber,
    patientSex: patientDesc.patientSex,
    patientAge: patientDesc.patientAge,
    height: patientDesc.height,
    weight: patientDesc.weight,
    disease: patientDesc.disease,
    assessmentDate: patientDesc.assessmentDate,
    assessmentResult: patientDesc.assessmentResult,

    patientNRS: patientDesc.patientNRS,
    patientMUST: patientDesc.patientMUST,

    treatmentStage: patientDesc.treatmentStage,
    hospitalizationStage: patientDesc.hospitalizationStage,
  }).then(res => {
    if (res.data.code == 200) {
      http_patient_findById()
      ElMessage.success("修改成功！")
    } else {
      ElMessage.error(res.data.message)
    }
  })
}
</script>

<style scoped lang="scss">
.container {
  background-color: #ffffff;
  height: 700px;
  padding-top: 30px;
}

.form {

}

.button {
  margin-left: 10%;
  width: 80%;
  height: 40px;
}
</style>
